package com.zik.rader_and_video.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @author: zhouxy
 * @description: 线城池
 * @date: 2023-03-26 18:35
 * @operation:
 **/
@Configuration
public class ThreadFactoryPoolsConfig {

    @Bean(value = "threadPoolInstance")
    public ExecutorService createThreadPoolInstance() {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("MqttAnalysis-thread-%d").build();
        return new ThreadPoolExecutor(
                20
                ,30
                ,1L
                , TimeUnit.MILLISECONDS
                ,new ArrayBlockingQueue<>(1000)
                ,threadFactory
                ,new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }
}
